package oppo;


import java.util.ArrayList;
import java.util.Arrays;

/**
 * @author Hang
 * @date 2022/9/2
 * @project AutumnOffer
 * @description
 **/
public class Solution2 {
    public static void main(String[] args) {
        ListNode node1 = new ListNode(3);
        node1.next = new ListNode(4);
        node1.next.next = new ListNode(1);
        ListNode node2 = new ListNode(5);
        node2.next = new ListNode(6);
        node2.next.next = new ListNode(2);
        ListNode listNode = combineTwoDisorderNodeToOrder(node1, node2);
        while (listNode!=null){
            System.out.println(listNode.val);
            listNode = listNode.next;
        }
    }
    public static ListNode combineTwoDisorderNodeToOrder (ListNode node1, ListNode node2) {
        // write code here
        ListNode node = new ListNode(0);
        ListNode res = node;
        ArrayList<Integer> list = new ArrayList<>();
        while(node1!=null){
            list.add(node1.val);
            node1 = node1.next;
        }
        while (node2!=null){
            list.add(node2.val);
            node2 = node2.next;
        }
        Object[] array = list.toArray();
        Arrays.sort(array);
        for(Object i:array){
            node.next = new ListNode((int)i);
            node = node.next;
        }
        node.next = null;
        return res.next;
    }
}
class ListNode {
    int val;
    ListNode next;
    ListNode(int x) { val = x; }
}